package com.ycj.entropy.data;

import androidx.room.Entity;
import androidx.room.PrimaryKey;

import com.alibaba.fastjson.JSON;
import com.ycj.entropy.util.IdGenerator;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

@Entity(tableName = "study")
public class Study implements Serializable {
    @PrimaryKey
    private long id;

    private String title;
    private String content;
    private String images;
    private long createAt;
    private String address;

    public Study() {
        if (id == 0) {
            genId();
        }
    }

    public Study(String title, String content,
                 Collection<String> images, long createAt, String address) {

        this();
        this.title = title;
        this.content = content;
        setImageList(images);
        this.createAt = createAt;
        this.address = address;
    }

    private void genId() {
        this.id = IdGenerator.INSTANCE.nextId();
    }

    public List<String> imageList() {
        return JSON.parseArray(this.images, String.class);
    }

    public void setImageList(Collection<String> images) {
        this.images = JSON.toJSONString(images);
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getCreateAt() {
        return createAt;
    }

    public void setCreateAt(long createAt) {
        this.createAt = createAt;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getImages() {
        return images;
    }

    public void setImages(String images) {
        this.images = images;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}


